package cn.xscrum.vtsp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspVolunteerActivity;
import cn.xscrum.vtsp.service.IVtspVolunteerActivityService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 志愿者关注活动Controller
 * 
 * @author xscrum
 * @date 2021-10-12
 */
@Controller
@RequestMapping("/vtsp/volunteerActivity")
public class VtspVolunteerActivityController extends BaseController
{
    private String prefix = "vtsp/volunteerActivity";

    @Autowired
    private IVtspVolunteerActivityService vtspVolunteerActivityService;

    @RequiresPermissions("vtsp:volunteerActivity:view")
    @GetMapping()
    public String activity()
    {
        return prefix + "/activity";
    }

    /**
	 * 查询志愿者关注活动列表
     */
    @RequiresPermissions("vtsp:volunteerActivity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspVolunteerActivity vtspVolunteerActivity)
    {
        startPage();
        List<VtspVolunteerActivity> list = vtspVolunteerActivityService.selectVtspVolunteerActivityList(vtspVolunteerActivity);
        return getDataTable(list);
    }

    /**
	 * 导出志愿者关注活动列表
     */
    @RequiresPermissions("vtsp:volunteerActivity:export")
    @Log(title = "志愿者关注活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspVolunteerActivity vtspVolunteerActivity)
    {
        List<VtspVolunteerActivity> list = vtspVolunteerActivityService.selectVtspVolunteerActivityList(vtspVolunteerActivity);
        ExcelUtil<VtspVolunteerActivity> util = new ExcelUtil<VtspVolunteerActivity>(VtspVolunteerActivity.class);
        return util.exportExcel(list, "activity");
    }

    /**
	 * 新增志愿者关注活动
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存志愿者关注活动
     */
    @RequiresPermissions("vtsp:volunteerActivity:add")
    @Log(title = "志愿者关注活动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspVolunteerActivity vtspVolunteerActivity)
    {
        return toAjax(vtspVolunteerActivityService.insertVtspVolunteerActivity(vtspVolunteerActivity));
    }

    /**
	 * 修改志愿者关注活动
     */
    @GetMapping("/edit/{volunteerId}")
    public String edit(@PathVariable("volunteerId") Long volunteerId, ModelMap mmap)
    {
        VtspVolunteerActivity vtspVolunteerActivity = vtspVolunteerActivityService.selectVtspVolunteerActivityById(volunteerId);
        mmap.put("vtspVolunteerActivity", vtspVolunteerActivity);
        return prefix + "/edit";
    }

    /**
	 * 修改保存志愿者关注活动
     */
    @RequiresPermissions("vtsp:volunteerActivity:edit")
    @Log(title = "志愿者关注活动", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspVolunteerActivity vtspVolunteerActivity)
    {
        return toAjax(vtspVolunteerActivityService.updateVtspVolunteerActivity(vtspVolunteerActivity));
    }

    /**
	 * 删除志愿者关注活动
     */
    @RequiresPermissions("vtsp:volunteerActivity:remove")
    @Log(title = "志愿者关注活动", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspVolunteerActivityService.deleteVtspVolunteerActivityByIds(ids));
    }
}
